In a system where multiple users desire concurrent access to the same data, a concurrency model such as exclusive concurrency can be used to provide such access. In such a model, each server instance manages an exclusive lock on a primary key and any data associated with that key. This lock is held for the length of the transaction when invoked for a transaction. In the case of a non-transactional invoke, such as for a method that requires access to, but will not update, the data, the lock is held until the method completes. In a clustered environment, it is possible that a given primary key is active in multiple servers. In such a situation, concurrency control is typically provided by the database.
The exclusive concurrency model works well in a single server system in which the server has exclusive access to the database. A sharing value, such as “db-is-shared” can be set to false, such that the any read of the data can read from an instance in an in-memory cache instead of reading from the database.
Problems arise, however, as the exclusive concurrency model requires the use of deadlocks. Deadlocking can occur when users have locks on separate objects, and one of the users is trying to acquire a lock on an object that is locked by another user. Beans holding instances of the data can also deadlock themselves if the beans are called within a transaction and subsequently called without a transaction.
Other systems provide the ability for each transaction to activate a unique instance of the data. These systems do not provide concurrency control within the application server, however, but rely on the database for concurrency. This database concurrency model is an improvement over exclusive concurrency, but it is still necessary to hit the database for every transaction. This approach can still strain system resources under load.